﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Classes.inventory.*;
    import Display.aswingui.*;
    import Display.PopulationUI.*;
    import Engine.*;
    import Display.hud.*;

    public class HUDPremiumGoodsComponent extends HUDComponent {

        private const m_textSize:int = 12;

        public var m_premiumGoodsSliderAsset:Class;
        public var m_premiumGoodsSlider:HUDPremiumGoodsComponent_m_premiumGoodsSliderAsset;
        public var m_goodsText:JTextField;
        public var m_premiumText:JTextField;
        protected var m_premiumPanel:JPanel;
        private var m_premiumAsset:DisplayObject;
        private var m_moreEnergyWindow:JWindow;
        protected var m_bReminderDown:Boolean = false;
        private var fullRatio:Number = 0.1;
        private var m_barberPole1:AutoAnimatedBitmap;
        private var m_barberPoleTimeout1:uint;
        protected var m_commodityPopup:CommodityPopup;
        protected var m_commodityTweenedAmount1:int;
        private var m_barberPole2:AutoAnimatedBitmap;
        private var m_barberPoleTimeout2:uint;
        protected var m_commodityTweenedAmount2:int;
        private var m_centerPremium2:JPanel;
        private var m_centerPremium:JPanel;
        private var m_premiumAlignHolder:JPanel;
        private var m_premiumTextHolder:JPanel;

        public function HUDPremiumGoodsComponent(_arg1:Function=null){
            this.m_premiumGoodsSliderAsset = HUDPremiumGoodsComponent_m_premiumGoodsSliderAsset;
            this.m_premiumGoodsSlider = (new HUDPremiumGoodsComponent_m_premiumGoodsSliderAsset() as HUDPremiumGoodsComponent_m_premiumGoodsSliderAsset);
            this.fullRatio = Global.gameSettings.getNumber("foodGoodsRatio", 0.1);
            super();
            this.m_premiumGoodsSlider.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver, false, 0, true);
            this.m_premiumGoodsSlider.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut, false, 0, true);
            this.m_premiumGoodsSlider.addEventListener(MouseEvent.CLICK, this.onClick, false, 0, true);
        }
        override public function get doubleBarComponent():Boolean{
            return (true);
        }
        override protected function buildComponent():void{
            m_jPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, 0);
            var _local1:TextFormat = new TextFormat(EmbeddedArt.DEFAULT_FONT_NAME_BOLD, this.m_textSize, 0xFFFFFF, true, false, false, null, null, TextFormatAlign.CENTER);
            var _local2:TextFormat = new TextFormat();
            _local2.align = TextFormatAlign.CENTER;
            this.m_premiumAlignHolder = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_premiumPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_premiumTextHolder = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_premiumTextHolder.setBorder(new EmptyBorder(null, new Insets(5, 35, 0, 0)));
            this.m_premiumText = ASwingHelper.makeTextField("0 ", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, this.m_textSize, 0xFFFFFF, 0, _local1);
            this.m_premiumText.filters = [new GlowFilter(0, 0.5, 3, 3, 10)];
            this.m_premiumText.setBorder(new EmptyBorder(null, new Insets(4)));
            this.m_centerPremium2 = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            this.m_centerPremium2.append(this.m_premiumText);
            this.m_centerPremium2.setPreferredWidth(126);
            this.m_premiumTextHolder.append(this.m_centerPremium2);
            this.m_goodsText = ASwingHelper.makeTextField("0 ", EmbeddedArt.DEFAULT_FONT_NAME_BOLD, this.m_textSize, 0xFFFFFF, 0, _local1);
            this.m_goodsText.filters = [new GlowFilter(0, 0.5, 3, 3, 10)];
            this.m_centerPremium = ASwingHelper.makeFlowJPanel(FlowLayout.CENTER);
            this.m_centerPremium.append(this.m_goodsText);
            this.m_centerPremium.setPreferredWidth(126);
            this.m_premiumTextHolder.append(this.m_centerPremium);
            ASwingHelper.setSizedBackground(this.m_premiumPanel, this.m_premiumGoodsSlider);
            this.m_premiumPanel.append(this.m_premiumTextHolder);
            this.m_premiumAlignHolder.append(this.m_premiumPanel);
            this.m_premiumAlignHolder.setBorder(new EmptyBorder(null, new Insets(3)));
            m_jPanel.append(this.m_premiumAlignHolder);
        }
        override protected function attachToolTip():void{
            m_toolTip = new ToolTip(function ():String{
                return (ZLoc.t("Main", "Premium_Goods_ToolTip", {
                    amount1:m_premiumText.getText(),
                    capacity1:Global.player.commodities.getCapacity(Commodities.PREMIUM_GOODS_COMMODITY).toString(),
                    amount2:m_goodsText.getText(),
                    capacity2:Global.player.commodities.getCapacity(Commodities.GOODS_COMMODITY).toString()
                }));
            });
            m_toolTip.attachToolTip(this);
            m_toolTip.hideCursor = true;
        }
        protected function onMouseOver(_arg1:MouseEvent):void{
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
        }
        protected function onClick(_arg1:MouseEvent):void{
            var _local2:Number;
            var _local3:Number;
            var _local4:Number;
            var _local5:StorageDialog;
            if (!Global.isVisiting()){
                _local2 = Global.player.commodities.getCapacity(Commodities.GOODS_COMMODITY);
                _local3 = Global.player.commodities.getCount(Commodities.GOODS_COMMODITY);
                _local4 = ((_local2 > 0)) ? Math.min((_local3 / _local2), 1) : 0;
                if ((_local3 / _local2) < this.fullRatio){
                    ResourceExplanationDialog.show(ResourceExplanationDialog.TYPE_NOT_ENOUGH_GOODS, true);
                } else {
                    _local5 = new StorageDialog();
                    UI.displayPopup(_local5);
                };
            };
        }
        protected function attachCommodityPopup(_arg1:Boolean, _arg2:Number):void{
            var _local3:Vector2;
            if (!this.m_commodityPopup){
                this.m_commodityPopup = new CommodityPopup(Commodities.GOODS_COMMODITY);
                this.addChild(this.m_commodityPopup);
                this.m_commodityPopup.hide();
            };
            if (this.m_commodityPopup){
                _local3 = this.getPopupPosition(_arg2);
                this.m_commodityPopup.setAppearPos(_local3);
                this.m_commodityPopup.x = _local3.x;
                this.m_commodityPopup.y = _local3.y;
                this.m_commodityPopup.forceUpdateValue(this.m_commodityTweenedAmount1);
                if (_arg1){
                    this.m_commodityPopup.show();
                };
            };
        }
        protected function getPopupPosition(_arg1:Number):Vector2{
            var _local2:MovieClip = (this.m_premiumGoodsSlider["sliderMask"] as MovieClip);
            var _local3:Vector2 = new Vector2();
            _local3.x = (0 - this.m_commodityPopup.m_supplyTooltip.width);
            _local3.y = (((1 - _arg1) * _local2.height) - 27);
            if (localToGlobal(_local3).y < 0){
                _local3.y = globalToLocal(new Point(0, 0)).y;
            };
            return (_local3);
        }
        override protected function setCounter1():void{
            m_counter1 = new HUDCapacityCounter(function (_arg1:Number, _arg2:Number):void{
                m_commodityTweenedAmount1 = _arg2;
                var _local3:* = Global.player.commodities.getCapacity(Commodities.GOODS_COMMODITY);
                var _local4:* = ((_local3 > 0)) ? Math.min(_arg1, 1) : 0;
                if ((((_local4 <= 0.1)) && ((_local4 > 0)))){
                    _local4 = 0.1;
                };
                var _local5:* = 48;
                var _local6:* = (m_premiumGoodsSlider.sliderMask2 as MovieClip);
                var _local7:* = (((_local4 - 1) * _local6.width) + _local5);
                _local6.x = _local7;
                var _local8:* = new TextFormat();
                _local8.align = TextFormatAlign.CENTER;
                m_goodsText.setTextFormat(_local8);
                m_goodsText.setText(Utilities.formatNumber(_arg2));
            });
            this.preparePanel();
        }
        override protected function setCounter2():void{
            m_counter2 = new HUDCapacityCounter(function (_arg1:Number, _arg2:Number):void{
                m_commodityTweenedAmount2 = _arg2;
                var _local3:* = Global.player.commodities.getCapacity(Commodities.PREMIUM_GOODS_COMMODITY);
                var _local4:* = ((_local3 > 0)) ? Math.min(_arg1, 1) : 0;
                if ((((_local4 <= 0.1)) && ((_local4 > 0)))){
                    _local4 = 0.1;
                };
                var _local5:* = 42;
                var _local6:* = (m_premiumGoodsSlider.sliderMask1 as MovieClip);
                var _local7:* = (((_local4 - 1) * _local6.width) + _local5);
                _local6.x = _local7;
                var _local8:* = new TextFormat();
                _local8.align = TextFormatAlign.CENTER;
                m_premiumText.setTextFormat(_local8);
                m_premiumText.setText(Utilities.formatNumber(_arg2));
            });
            this.preparePanel();
        }
        private function preparePanel():void{
            ASwingHelper.prepare(this.m_premiumText);
            ASwingHelper.prepare(this.m_goodsText);
            ASwingHelper.prepare(this.m_centerPremium2);
            ASwingHelper.prepare(this.m_centerPremium);
            ASwingHelper.prepare(this.m_premiumTextHolder);
            ASwingHelper.prepare(this.m_premiumAlignHolder);
            ASwingHelper.prepare(this.m_premiumPanel);
            ASwingHelper.prepare(m_jPanel);
        }

    }
}//package Display.hud.components 
